package com.foundjet.ymorder.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.foundjet.back.order.model.Order;
import com.foundjet.back.order.model.OrderItem;
import com.foundjet.ymorder.dao.OrderDao;

@Service
public class OrderService {
	@Resource
	private OrderDao dao;
	
	
	public List<Order> getAllOrder(int userId) {
		List<Order> orders = dao.getAllOrder(userId);
		if (orders != null && orders.size() >0) {
			for (int i = 0, length = orders.size(); i < length; i++) {
				String [] orderItemIds = orders.get(i).getOrderItemId().split(",");
				int[] ids = new int[orderItemIds.length];
				for (int j = 0; j < orderItemIds.length; j++) {
					ids[j] = Integer.parseInt(orderItemIds[j]);
				}
				List<OrderItem> items = dao.getOrderItemByIds(ids);
				orders.get(i).setOrderItemList(items);
			}
		}
		return orders;
	}
}
